﻿using BLL;
using DAL;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Model;

namespace HoteCode.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class PaiRoomController : ControllerBase
    {
        public PaiRoomBLL PaiRoomBLL { get; }
        public ILogger<PaiRoomController> Logger { get; }

        public PaiRoomController(PaiRoomBLL paiRoomBLL, ILogger<PaiRoomController> logger)
        {
            PaiRoomBLL = paiRoomBLL;
            Logger = logger;
        }
        [HttpPost]
        /// <summary>
        /// 排房添加
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public IActionResult PaiRoomAdd(PaiRoomMoodel info)
        {
            try
            {
                Logger.LogInformation($"管理员正在添加排房数据,添加成功,添加时间为{DateTime.Now}");
                int res = PaiRoomBLL.PaiRoomAdd(info);
                return Ok(res);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpGet]
        /// <summary>
        /// 显示查询分页
        /// </summary>
        /// <param name="totalCount">页容量</param>
        /// <param name="totalPage">页码</param>
        /// <param name="Pageindex">当前页</param>
        /// <param name="PageSize">页码</param>
        /// <returns></returns>
        public IActionResult GetPaiRooList( int Pageindex = 1, int PageSize = 2)
        {
            try
            {
                int totalCount = 0; int totalPage = 0;
                var list = PaiRoomBLL.GetPaiRooList(out totalCount, out totalPage, Pageindex, PageSize);
                return Ok(new
                {
                    list = list,
                    totalCount = totalCount,
                    totalPage = totalPage
                });
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpDelete]
        /// <summary>
        /// 逻辑删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IActionResult PaiRoomDel(int id)
        {
            try
            {
                var res = PaiRoomBLL.PaiRoomDel(id);
                return Ok(res);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpDelete]
        /// <summary>
        /// 批量逻辑删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public IActionResult PaiRoomDelAll(string ids)
        {
            try
            {
                Logger.LogInformation($"管理员正在删除数据,删除成功,删除时间为{DateTime.Now}");
                var res = PaiRoomBLL.PaiRoomDelAll(ids);
                return Ok(res);
            }
            catch (Exception)
            {
                Logger.LogInformation($"管理员正在删除数据,删除失败");
                throw;
            }
        }
        [HttpPut]
        /// <summary>
        /// 批量修改状态
        /// </summary>
        /// <param name="ids"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public IActionResult PaiRoomUptAll(string ids, int state)
        {
            try
            {
                Logger.LogInformation($"管理员正在删除数据,删除成功,删除时间为{DateTime.Now}");
                var res = PaiRoomBLL.PaiRoomUptAll(ids, state);
                return Ok(res);
            }
            catch (Exception)
            {
                Logger.LogInformation($"管理员正在删除数据,删除失败");
                throw;
            }
        }
        [HttpGet]
        /// <summary>
        /// Id查询(反填)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IActionResult GetPaiRoomId(int id)
        {
            try
            {
                var list = PaiRoomBLL.GetPaiRoomId(id);
                return Ok(list);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpPut]
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public IActionResult GetRPaiRoomUpdate(PaiRoomMoodel info)
        {
            try
            {
                Logger.LogInformation($"管理员正在删除数据,删除成功,删除时间为{DateTime.Now}");
                var list = PaiRoomBLL.GetRPaiRoomUpdate(info);
                return Ok(list);
            }
            catch (Exception)
            {
                Logger.LogInformation($"管理员正在删除数据,删除失败");
                throw;
            }
        }
    }
}
